package com.briup;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Classname CreatTable
 * @Description TODO
 * @Date 2023/11/21 15:12
 * @Created by 崔宗祺
 * @Version v1.0.0
 */
public class CreatTable {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        try {
            //加载注册驱动
            Class.forName("oracle.jdbc.driver.OracleDriver");
            //获取链接对象
            connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "bttc2", "system");
            //获取Statement对象
            statement = connection.createStatement();
            //执行SQL语句
            for (int i = 1; i <= 31; i++) {
                String sql = "create table e_detail_" + i + "("
                        + "name varchar2(50) not null,"
                        + "srcId varchar2(50) not null,"
                        + "desId varchar2(50) not null,"
                        + "devId varchar2(50) not null,"
                        + "count number,"
                        + "cmd varchar2(50) not null,"
                        + "data number,"
                        + "status number,"
                        + "gatherDate date "
                        + ")";
                int rows = statement.executeUpdate(sql);
                System.out.println(rows);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            try {
                if (connection != null) {
                    connection.close();
                }
                if (statement != null) {
                    statement.close();
                }
            } catch (SQLException throwable) {
                throwable.printStackTrace();
            }

        }
    }
}
